var ws = require('nodejs-websocket');
var conn;
var server = ws.createServer(function(socket){
	conn = socket;
    socket.on('text', function(str) {
        console.log('text', str);
    });
    socket.on('close', function(code) {
		console.log('close', code)
		conn = null;
    })
    socket.on('error', function(code) {
		console.log('error', code)
		conn = null;
    })
}).listen(3000);
setInterval(function(){
	if(conn){
		conn.sendText('to be or not to be');
	}
},1000)
